package com.ylkj.patient.moduleimpl;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.examination.mlib.constants.PatientUrl;
import com.examination.mlib.constants.ProjectConfigure;
import com.examination.mlib.constants.UserInfoConstants;
import com.example.loginmodule.CenterActivity;
import com.example.messagemodule.utils.MessageUtils;
import com.yilijk.base.AppBase;
import com.yilijk.base.BaseApi;
import com.yilijk.base.constants.UserInfo;
import com.yilijk.base.network.RequestParams;
import com.yilijk.base.network.config.BaseRouter;
import com.yilijk.base.network.config.BaseUrl;
import com.yilijk.base.network.https.HttpUtils;
import com.yilijk.base.network.https.NetAttestationUtils;
import com.yilijk.base.utils.ActivityManagerUtils;
import com.yilijk.base.utils.DevicesUtils;
import com.yilijk.base.utils.SharedPreferencesUtils;
import com.yljk.mcconfig.constants.MCApi;
import com.ylkj.patient.BuildConfig;
import com.ylkj.patient.MainApplication;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by SHICHENG
 * <p>
 * Time on
 */
@Route(path = BaseRouter.Base)
public class AppBaseImpl implements BaseApi {
    @Override
    public boolean isOpenAttestation() {
        return ProjectConfigure.Open.isOpenAttestation;
    }

    @Override
    public boolean isOpenSendEvent() {
        return ProjectConfigure.Open.isSendEvent;
    }

    @Override
    public String[] rnUpdataUrl() {
        return new String[]{
                "/api/app2",
        };
    }

    @Override
    public int getDominNo() {
//        return BuildConfig.DOMIN_NO;
        return MainApplication.LocalDominNo;
    }

    @Override
    public String getDomin() {
//        return "https://apitest.yilijk.com";
        return MainApplication.LocalDominNo == 0 ? BaseUrl.DOMIN.d1 :
                MainApplication.LocalDominNo == 1 ? BaseUrl.DOMIN.t1 :
                MainApplication.LocalDominNo == 2 ? "https://api.t2.yilijk.com" :
                        MainApplication.LocalDominNo == 3 ? BaseUrl.DOMIN.pre :
                                BaseUrl.DOMIN.api;
    }

    @Override
    public String getWebUrl() {
        return MainApplication.LocalDominNo == 0 ? BaseUrl.WEB.d1 :
                MainApplication.LocalDominNo == 1 ? BaseUrl.WEB.t1 :
                MainApplication.LocalDominNo == 2 ? BaseUrl.WEB.t1 :
                        MainApplication.LocalDominNo == 3 ? BaseUrl.WEB.pre :
                                BaseUrl.WEB.api;
    }

    @Override
    public String getH5Url() {
        return MainApplication.LocalDominNo == 0 ? BaseUrl.H5.d1 :
                MainApplication.LocalDominNo == 1 ? BaseUrl.H5.t1 :
                MainApplication.LocalDominNo == 2 ? BaseUrl.H5.t1 :
                        MainApplication.LocalDominNo == 3 ? BaseUrl.H5.pre :
                                BaseUrl.H5.api;
    }

    @Override
    public String getPointUrl() {
        return MainApplication.LocalDominNo == 0 ? PatientUrl.point_d1 :
                MainApplication.LocalDominNo == 1 ? PatientUrl.point_t1 :
                MainApplication.LocalDominNo == 2 ? PatientUrl.point_t2 :
                        PatientUrl.point_api;
    }

    @Override
    public String getOssPath() {
        return "patient";
    }

    @Override
    public String getTerminal() {
        return "7";
    }

    @Override
    public String getApkType() {
        return BuildConfig.APK_TYPE;
    }

    @Override
    public void onCancelLogout(Activity activity) {
        if (activity == null){
            activity = ActivityManagerUtils.getLastestActivity();
        }
        //删除本地
        //成功删除本地缓存数据
        boolean b = SharedPreferencesUtils.getInstance().removeAll(AppBase.getApplication());
        if (b){
            MessageUtils.logoutIM();
            NetAttestationUtils.getInstance().setSALT("");
            ActivityManagerUtils.finishAllActivity();
            Intent intent = new Intent(activity, CenterActivity.class);
            intent.putExtra("isLogout",true);
            activity.startActivity(intent);
            activity.finish();
        }
    }

    @Override
    public String[] noSign() {
        return new String[]{
            MCApi.Live.LIVE_SET_VIEWER_COUNT,
    };
    }

    @Override
    public boolean isEnvironment() {
        return MainApplication.LocalDominNo != 3 && MainApplication.LocalDominNo!=4;
    }

    @Override
    public boolean isOnline() {
        return MainApplication.LocalDominNo == 4;
    }

    @Override
    public RequestParams getClickParams(JSONObject jsonObject) {
        RequestParams params = new RequestParams();
        params.put("appId",8);
        params.put("secretKey","jh86ch26ch");
        params.put("terminal", DevicesUtils.getTerminal());
        try {
            jsonObject.put("visitid",SharedPreferencesUtils.getInstance().getString("visitid",null));
            jsonObject.put("uuid",SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_openId,""));
            jsonObject.put("passportId",SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_passportId,""));
        } catch (JSONException e) {
            e.printStackTrace();
        }
        params.put("log",jsonObject.toString());
        return params;
    }

    @Override
    public boolean isUserAgreeChecked() {
        return MainApplication.getMainApplication().isUserAgreeChecked();
    }

    @Override
    public void init(Context context) {

    }
}
